/*
 * Powered By [pkuWx]
 * Web Site: http://www.wuxi.ss.pku.edu.cn
 * Since 2015 - 2015
 */

package cn.edu.pku.wxlib.role.dao;

import java.util.*;

import cn.edu.pku.wxlib.adminuser.vo.query.AdminuserQuery;
import cn.edu.pku.wxlib.role.model.*;
import cn.edu.pku.wxlib.role.service.*;
import cn.edu.pku.wxlib.role.vo.query.*;
import cn.org.rapid_framework.page.PageRequest;
import javacommon.base.*;
import javacommon.util.*;
import javacommon.page.Page;

/**
 * @version 1.0
 * @since 1.0
 */








import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;


@Repository
public class RoleDao extends BaseIbatis3Dao<Role,RoleQuery,java.lang.Integer>{
	
	@Override
	public String getIbatisMapperNamesapce() {
		return "Role";
	}
	
	public void saveOrUpdate(Role entity) {
		if(entity.getRoleId() == null) 
			save(entity);
		else 
			update(entity);
	}
	
	public Page findPage(RoleQuery query) {
		return pageQuery("Role.findPage",query);
	}

	//根据adminId查找未分配的角色
	public Page listUnknownRoleByAdmin(PageRequest<Map> pageRequest) {
		return pageQuery("Role.listUnknownRoles",pageRequest);
	}
	
	//生成map
	protected Map<?, ?> map(final Object... datas) {
		Assert.isTrue(datas.length%2==0, "参数必须为偶数个");
		final Map<Object, Object> map = new HashMap<Object, Object>();
		for (int i = 0; i < datas.length; i += 2) {
			map.put(datas[i], datas[i+1]);
		}
		return map;
	}
	//根据adminId查找已分配的角色
	public Page listRoleByAdmin(AdminuserQuery query) {
		return pageQuery("Role.listRoles",query);
	}
}
